import { apiClient } from '@/lib/api-client';
import type { ApiResponse } from '@/lib/types/api';

interface Memo {
  _id: string;
  userId: string;
  content: string;
  advice?: string;
  mood?: {
    level: 1 | 2 | 3 | 4 | 5;
  };
  createdAt: Date;
  updatedAt: Date;
}

interface CreateMemoRequest {
  content: string;
  mood?: {
    level: 1 | 2 | 3 | 4 | 5;
  };
}

export class MemoService {
  // 获取所有笔记
  static async getMemos(): Promise<ApiResponse<Memo[]>> {
    return await apiClient<null, Memo[]>('/memo', {
      method: 'GET',
    });
  }

  // 创建笔记并获取AI建议
  static async createMemo(data: CreateMemoRequest): Promise<ApiResponse<Memo>> {
    return await apiClient<CreateMemoRequest, Memo>('/memo', {
      method: 'POST',
      body: data,
    });
  }

  // 更新笔记
  static async updateMemo(memoId: string, data: Partial<CreateMemoRequest>): Promise<ApiResponse<Memo>> {
    return await apiClient<Partial<CreateMemoRequest>, Memo>(`/memo/${memoId}`, {
      method: 'PUT',
      body: data,
    });
  }

  // 删除笔记
  static async deleteMemo(memoId: string): Promise<ApiResponse<void>> {
    return await apiClient<null, void>(`/memo/${memoId}`, {
      method: 'DELETE',
    });
  }

  // 获取单个笔记
  static async getMemo(memoId: string): Promise<ApiResponse<Memo>> {
    return await apiClient<null, Memo>(`/memo/${memoId}`, {
      method: 'GET',
    });
  }
}

export type { Memo, CreateMemoRequest };
